﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace YXShop.Web.admin.product
{
    public partial class productother_list : System.Web.UI.Page
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string classValue = ChangeHope.WebPage.PageRequest.GetString("classValue");
                if (classValue != "")
                {
                    ViewState["ClassValue"] = classValue;
                }
                int productTypeId = ChangeHope.WebPage.PageRequest.GetInt("id");
                if (productTypeId > 0)
                {
                    BindInfo(productTypeId);
                    ViewState["productTypeId"] = productTypeId;
                }
                this.BrandInfo();
            }
        }

        private void BindInfo(int id)
        {
            YXShop.BLL.Product.ProductType bll = new YXShop.BLL.Product.ProductType();
            YXShop.Model.Product.ProductType model = bll.GetModel(id);
            if (model != null)
            {
                if (model.RelevanceBrand != "" && model.RelevanceBrand != string.Empty)
                {
                    this.BrandInfo(model.RelevanceBrand);
                }
                else
                {
                    this.ltBrandSelected.Text = "<select size=\"14\" name=\"selBrandIdSelected\" multiple=\"multiple\" style=\"width: 98%\"></select>";
                }
            }
            else
            {
                this.ltBrandSelected.Text = "<select size=\"14\" name=\"selBrandIdSelected\" multiple=\"multiple\" style=\"width: 98%\"></select>";
            }
        }

        private void BrandInfo()
        {
            YXShop.BLL.Product.ProductBrand bll = new YXShop.BLL.Product.ProductBrand();
            List<YXShop.Model.Product.ProductBrand> list = bll.GetDTList("");
            StringBuilder brandSel = new StringBuilder();
            brandSel.Append("<select size=\"14\" id=\"selBrandId\" style=\"width: 100%\">");
            brandSel.Append("<option value=''></option>");
            if (list.Count > 0)
            {
                foreach (YXShop.Model.Product.ProductBrand brand in list)
                {
                    brandSel.Append("<option value='"+brand.ID.ToString()+"'>"+brand.Name.ToString()+"</option>");
                }
                
            }
            brandSel.Append("</select>");
            this.ltBrandList.Text = brandSel.ToString();
        }

        private void BrandInfo(string strBrandId)
        {
            YXShop.BLL.Product.ProductBrand bll = new YXShop.BLL.Product.ProductBrand();
            List<YXShop.Model.Product.ProductBrand> list = bll.GetDTList("");
            StringBuilder brandSel = new StringBuilder();
            brandSel.Append("<select size=\"14\" name=\"selBrandIdSelected\" multiple=\"multiple\"  style=\"width: 98%\">");
            if (list.Count > 0)
            {
                foreach (YXShop.Model.Product.ProductBrand brand in list)
                {
                    brandSel.Append("<option value='" + brand.ID.ToString() + "' selected>" + brand.Name.ToString() + "</option>");
                }
            }
            brandSel.Append("</select>");
            this.ltBrandSelected.Text = brandSel.ToString();
        }

        protected void button4_Click(object sender, EventArgs e)
        {
            YXShop.BLL.Product.ProductType bll = new YXShop.BLL.Product.ProductType();
            string brandId=ChangeHope.WebPage.PageRequest.GetFormString("selBrandIdSelected");
            if (bll.Amend(Convert.ToInt32(ViewState["productTypeId"]), "RelevanceBrand", brandId) > 0)
            {
                if (ViewState["ClassValue"] != null)
                {
                    string classValue = ViewState["ClassValue"].ToString();
                    if (classValue.Contains("4"))
                    {
                        Response.Redirect("productbuyset_list.aspx?classValue=" + ViewState["ClassValue"] + "&id=" + ViewState["productTypeId"] + "");
                    }
                    else
                    {
                        ChangeHope.WebPage.BasePage.PageRight("保存成功。", "product_type_list.aspx");
                    }
                }
                else
                {
                    ChangeHope.WebPage.BasePage.PageRight("保存成功。", "product_type_list.aspx");
                }
            }

        }

        protected void Back_Click(object sender, EventArgs e)
        {
            if (ViewState["ClassValue"] != null)
            {
                string classValue = ViewState["ClassValue"].ToString();
                if (classValue.Contains("1"))
                {
                    Response.Redirect("productproperty_list.aspx?classValue=" + ViewState["ClassValue"] + "&id=" + ViewState["productTypeId"] + "");
                }
                else if (classValue.Contains("2"))
                {
                    Response.Redirect("productparameter_list.aspx?classValue=" + ViewState["ClassValue"] + "&id=" + ViewState["PropertyId"] + "");
                }
                else
                {
                    Response.Redirect("product_type_edit.aspx?backType=Set&id=" + ViewState["productTypeId"] + "");
                }
            }
            else
            {
                Response.Redirect("product_type_edit.aspx?backType=Set&id=" + ViewState["productTypeId"] + "");
            }
        }
    }
}
